﻿Public Class ListMemo

#Region "重载删除事件"
    Private _Id As String = ""
    Public Overrides Function DoDelete() As Boolean
        Dim CMD As New ADODB.Command
        CMD.CommandText = "DELETE from MEMO  where ID='" + _Id + "'"
        If ct.ExcCommand(CMD) Then
            CMD.CommandText = "DELETE from EnglishMEMO  where MemoID='" + _Id + "'"
            If ct.ExcCommand(CMD) Then
                ShowMessageBox("删除成功")
            Else
                ShowMessageBox("删除失败")
            End If
        Else
            ShowMessageBox("删除失败")
        End If
        LoadData()
        Return True

    End Function
#End Region

#Region "删除CHECK"
    Public Overrides Function DoDeleteCheck() As Boolean
        DoDeleteCheck = False
        If ShowMessageResult("是否删除本条记录") = Windows.Forms.DialogResult.No Then Exit Function
        If _Id = "" Then
            ShowMessageBox("没有选中任何备注")
            Exit Function
        End If
        DoDeleteCheck = True
    End Function
#End Region

#Region "重载插入"
    Public Overrides Function DoInsert() As Boolean
        MyBase.DoInsert()
        Using frm As New Memo
            frm.iType = Me.iType
            frm.strName = Me.strName
            frm.ShowDialog()
            If frm.bAdd Then
                LoadData()
            End If
        End Using
        Return True
    End Function
#End Region

#Region "加载数据"
    Public Overrides Sub LoadData()

        ''A-2009-10-11
        'If GetAppSettingConfig("BrowserOtherUserData") <> "1" Then
        '    Me.MyDataView1.UserNameValue = Me.strName
        '    Me.MyDataView1.UserName = "USERNAME"
        '    Me.MyDataView1.BrowserData = False
        'End If
        ''A-2009-10-11

        Dim strSql_1 As String
        Dim strSql1_1 As String
        strSql_1 = "select ID,TITLE  from MEMO                 Where 1=1 "
        If Me.cbo类型.Text.Trim <> "" Then
            strSql_1 &= " And type=" & (Me.cbo类型.SelectedIndex)
        End If
        strSql_1 &= " ORDER BY OPTIME DESC"
        strSql1_1 = "select count(*) as PageCount from MEMO  Where 1=1  "
        If Me.cbo类型.Text.Trim <> "" Then
            strSql1_1 &= " And type=" & (Me.cbo类型.SelectedIndex)
        End If
        Me.MyDataView1.SetRsSQLITE(strSql_1, strSql1_1, ct, 1)
    End Sub
#End Region

    Public Overrides Function DoSelect(ByVal strId As String) As Boolean
        Me._Id = strId
        Return MyBase.DoSelect(strId)
    End Function
    Private Sub cbo类型_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        LoadData()
    End Sub

#Region "窗体数据保存的重载方法 A-2010-09-06"
    Public Overrides Sub 保存窗体数据到数据库(ByRef dtData As System.Data.DataTable)
        dtData.Rows.Add(New Object() {"类型", "", Me.cbo类型.SelectedIndex.ToString})
    End Sub

    Public Overrides Sub 存取数据库数据到窗体(ByVal dtDbData As System.Data.DataTable)
        Dim index As Integer = 查找数据("类型", "", "1", dtDbData)
        If index > 0 Then
            Me.cbo类型.SelectedIndex = index
        End If
    End Sub

#End Region

    Private Sub MyDataView1_ItemDoubleClickRefreshData(ByVal strId As System.String, ByRef bState As System.Boolean) Handles MyDataView1.ItemDoubleClickRefreshData
        Using frm As Memo = New Memo
            frm.参数列表.Add("ID", strId)
            frm.模式 = Wys.Control.Vb.InsertFormBase.模式型.修正
            frm.iType = Me.iType
            frm.strName = Me.strName
            frm.ShowDialog()

            If frm.bAdd Then
                LoadData()
            End If
        End Using
    End Sub
End Class
